#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct LNode {
  ElemType data;
  struct LNode *next;
} LNODE;
typedef struct list {
  struct LNode *head;
  int size;
} LIST;
void InitList(LIST *list) {
  list->size = 0;
  list->head = (struct LNode*)malloc(sizeof(struct LNode));
  list->head->next = NULL;
}
void PreInsert(LIST *list, ElemType elem) {
  LNODE *node = (LNODE*)malloc(sizeof(LNODE));
  node->data = elem;
  node->next = NULL;
  LNODE *hNext = list->head->next;
  list->head->next = node;
  node->next = hNext;
  ++list->size;
} void DelAtPos(LIST *list, int pos) {
  if (pos < 0 || pos >= list->size)
    return ;
  LNODE *p = list->head;
  while (pos--)
    p = p->next;
  LNODE *q = p->next;
  p->next = q->next;
  free(q);
  --list->size;
}
void PreDel(LIST *list) {
  DelAtPos(list, 0);
}
void Disp(LIST *list) {
  LNODE *p = list->head->next;
  while (p) {
    printf("%d ", p->data);
    p = p->next;
  }
  printf("\n");
}

int main(void) {
  LIST list;
  InitList(&list);
  int i;
  for (i = 0; i < 10; i++) {
    PreInsert(&list, i);
    Disp(&list);
  }
  for (i = 0; i < 20; i++) {
    //PreDel(&list);
    DelAtPos(&list, list.size / 2);
    Disp(&list);
  }
  return EXIT_SUCCESS;
}
